package com.tarena.practice.manage.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tarena.practice.manage.mapper.CommentMapper;
import com.tarena.practice.manage.pojo.Comment;
import com.tarena.practice.manage.vo.PageUtils;

@Service
public class CommentService {

	@Autowired
	private CommentMapper commentMapper;
	public PageUtils<Comment> queryCommentsByTopicId(Integer pageNum, Integer pageSize, Integer topicId) {
		PageUtils<Comment> commentPage = new PageUtils<>();
		commentPage.setPageSize(pageSize);
		commentPage.setCurrentPage(pageNum);
		commentPage.setOptionI(topicId);
		List<Comment> comments = commentMapper.queryCommentsByTopicId(commentPage);
		Integer count = commentMapper.getCommentCount(commentPage);
		commentPage.setList(comments);
		commentPage.setTotalRow(count);
		commentPage.setListNum(comments.size());
		return commentPage;
	}

}
